(navigation image)
Home Animation & Cartoons | Arts & Music | Community Video | Computers & Technology | Cultural & Academic Films | Ephemeral Films | Movies | News & Public Affairs | Prelinger Archives | Spirituality & Religion | Sports Videos | Television | Videogame Videos | Vlogs | Youth Media
Search: Advanced Search
Anonymous User (login or join us) Upload

View movie

[item image]
View thumbnails
Run time: 20 minutes 58 seconds

Play / Download (help[help])

(27.4 M)Ogg Video
(48.4 M)h.264
(64.3 M)QuickTime


All Files: HTTP
[Attribution-Noncommercial-Share Alike 3.0]

Resources

Bookmark

Johan Falk/NodeOneLearn Drupal 13f: Taking care of form data

You are using our new video/audio player!
I prefer flash (when possible)
Give us feedback!

This screencast is a part of the epic learning series "Four weeks of Drupal", chapter "Writing a module". You can view the full series at http://dev.nodeone.se/en/four-weeks-of-drupal.

Please post any comments over there, or we won't see them. Sorry.
---
This screencast shows some more aspects of form API, namely how to write functions that are called when forms are submitted. It also includes how to set default values for form elements. In more detail, this screencast includes:
* That functions named FORM_ID_submit($form, $form_state) will by default be called on form submissin
* That data storing should NOT be done by the form submit function, but by a separate function (since data handling should be possible to do without any forms)
* That submitted values can be found in $form_state['input']
* The two functions variable_set and variable_get, used for storing simple and small variables
* That the property #defaule_value can be used to set default values for form elements
* An example of how to use the implode() and explode() functions to manage line breaks

code added/changed in wordlist.module

/**
* Builds the form for configuring Word list.
*/
function wordlist_page() {
$form['wordlist_words'] = array(
'#type' => 'textarea',
'#title' => t('Words to inlcude in the list'),
'#description' => t('The words included in this list will be available to Rules and other modules making use of the global "site" entity.'),
'#default_value' => implode("\r\n", variable_get('wordlist_words', array())),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save')
);

return $form;
}

/**
* Submit function for the Word list configuration page.
*/
function wordlist_page_submit($form, $form_state) {
// Break up the list of words according to line breaks.
$words = explode("\r\n", $form_state['input']['wordlist_words']);

wordlist_save_list($words);
drupal_set_message(t('The words have been saved!'));
}

/**
* Stores the globally accessible Word list words.
* @param $words
* An array containing the words that should be stored.
*/
function wordlist_save_list(array $words) {
variable_set('wordlist_words', $words);
}

---
This screencast is a part of the epic learning series "Four weeks of Drupal", chapter "Writing a module". You can view the full series at http://dev.nodeone.se/en/four-weeks-of-drupal.

Please post any comments over there, or we won't see them. Sorry.


This movie is part of the collection: Community Video

Producer: Johan Falk/NodeOne
Audio/Visual: sound
Keywords: Drupal; 4 weeks of Drupal; NodeOne; coding

Creative Commons license: Attribution-Noncommercial-Share Alike 3.0


Individual Files

Movie Files QuickTime h.264 Ogg Video
Drupal 13f - Form submission 64.3 MB
48.4 MB
27.4 MB
Image Files Animated GIF Thumbnail
Drupal 13f - Form submission 218.7 KB
4.0 KB
Information FormatSize
LearnDrupal13fTakingCareOfFormData_files.xml Metadata [file]
LearnDrupal13fTakingCareOfFormData_meta.xml Metadata 3.1 KB

Be the first to write a review
Downloaded 46 times
Reviews


Terms of Use (10 Mar 2001)